home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / fpc / compiler / browser.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-24  |  4KB  |  167 lines

  1. {
  2.     $Id: browser.pas,v 1.1.1.1 1998/03/25 11:18:12 root Exp $
  3.     Copyright (c) 1996-98 by Florian Klaempfl
  4.  
  5.     This unit implements a browser object
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. }
  21.  
  22. unit browser;
  23.  
  24. interface
  25.  
  26. uses globals, files;
  27.  
  28. type
  29.   pref = ^tref;
  30.   tref = object
  31.          nextref   : pref;
  32.          inputfile : pinputfile;
  33.          lineno    : longint;
  34.          constructor init(ref : pref);
  35.          constructor load(var ref : pref;fileindex : word;line : longint);
  36.          destructor done; virtual;
  37.          function  get_file_line : string;
  38.          end;
  39.  
  40.   { simple method to chain all refs }
  41.   procedure add_new_ref(var ref : pref);
  42.  
  43.   function get_source_file(index : word) : pinputfile;
  44.  
  45.   { one big problem remains for overloaded procedure }
  46.   { we should be able to separate them               }
  47.   { this might be feasable in pass_1                 }
  48.  
  49. implementation
  50.  
  51.   constructor tref.init(ref :pref);
  52.  
  53.     begin
  54.        nextref:=nil;
  55.        if ref<>nil then
  56.           ref^.nextref:=@self;
  57.        if current_module<>nil then
  58.          begin
  59.             inputfile:=current_module^.current_inputfile;
  60.             if inputfile<>nil then
  61.               begin
  62.                  inc(inputfile^.ref_index);
  63.                  lineno:=inputfile^.line_no;
  64.               end
  65.             else
  66.               lineno:=0;
  67.          end
  68.        else
  69.          begin
  70.             inputfile:=nil;
  71.             lineno:=0;
  72.          end;
  73.     end;
  74.  
  75.   constructor tref.load(var ref : pref;fileindex : word;line : longint);
  76.  
  77.     begin
  78.        if assigned(ref) then
  79.          ref^.nextref:=@self;
  80.        nextref:=nil;
  81.        inputfile:=get_source_file(fileindex);
  82.        lineno:=line;
  83.        ref:=@self;
  84.     end;
  85.  
  86.   destructor tref.done;
  87.  
  88.     begin
  89.        if inputfile<>nil then
  90.          dec(inputfile^.ref_count);
  91.     end;
  92.  
  93.     function tref.get_file_line : string;
  94.  
  95.       begin
  96.         get_file_line:='';
  97.         if inputfile=nil then exit;
  98. {$ifdef USE_RHIDE}
  99.         get_file_line:=lowercase(inputfile^.name^+inputfile^.ext^)+':'+tostr(lineno)+':'
  100. {$else  USE_RHIDE}
  101.         get_file_line:=inputfile^.name^+inputfile^.ext^+'('+tostr(lineno)+')'
  102. {$endif USE_RHIDE}
  103.       end;
  104.  
  105.   procedure add_new_ref(var ref : pref);
  106.  
  107.     var
  108.        newref : pref;
  109.  
  110.     begin
  111.        new(newref,init(ref));
  112.        ref:=newref;
  113.     end;
  114.  
  115.     function get_source_file(index : word) : pinputfile;
  116.  
  117.       var
  118.          f : pinputfile;
  119.  
  120.       begin
  121.          get_source_file:=nil;
  122.          f:=pinputfile(current_module^.sourcefiles.files);
  123.          while assigned(f) do
  124.            begin
  125.               if f^.ref_index=index then
  126.                 begin
  127.                    get_source_file:=f;
  128.                    exit;
  129.                 end;
  130.               f:=pinputfile(f^._next);
  131.            end;
  132.       end;
  133.  
  134. end.
  135. {
  136.   $Log: browser.pas,v $
  137.   Revision 1.1.1.1  1998/03/25 11:18:12  root
  138.   * Restored version
  139.  
  140.   Revision 1.5  1998/03/10 16:27:36  pierre
  141.     * better line info in stabs debug
  142.     * symtabletype and lexlevel separated into two fields of tsymtable
  143.     + ifdef MAKELIB for direct library output, not complete
  144.     + ifdef CHAINPROCSYMS for overloaded seach across units, not fully
  145.       working
  146.     + ifdef TESTFUNCRET for setting func result in underfunction, not
  147.       working
  148.  
  149.   Revision 1.4  1998/03/10 01:17:15  peter
  150.     * all files have the same header
  151.     * messages are fully implemented, EXTDEBUG uses Comment()
  152.     + AG... files for the Assembler generation
  153.  
  154.   Revision 1.3  1998/03/02 01:48:06  peter
  155.     * renamed target_DOS to target_GO32V1
  156.     + new verbose system, merged old errors and verbose units into one new
  157.       verbose.pas, so errors.pas is obsolete
  158.  
  159.   Revision 1.2  1998/02/13 10:34:37  daniel
  160.   * Made Motorola version compilable.
  161.   * Fixed optimizer
  162.  
  163.   Revision 1.1.1.1  1997/11/27 08:32:51  michael
  164.   FPC Compiler CVS start
  165. }
  166.  
  167.